public class QuickSlowNodeForEach {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
//        boolean node = hasCycle(head);
        int n = 19;
//        boolean node = happynum(n);
//        System.out.println("node = " + node);
        ListNode node = middleNode(head);
        while (node!=null){
            System.out.println("node.val = " + node.val);
            node = node.next;
        }
    }

    private static ListNode middleNode(ListNode head) {
        return null;
    }

    private static boolean happynum(int n) {
        if(n<10) {
            if (n == 1) return true;
            else return false;
        }
        char[] chars = (n + "").toCharArray();
        while (chars.length!=1){
            chars = getValue(chars);
        }
        if(chars[0]=='1')
            return true;
        else
            return false;
    }

    private static char[] getValue(char[] chars) {
        int result = 0;
        for (int i = 0; i < chars.length; i++) {
            result += Math.pow(chars[i]-'0',2);
        }
        return (result+"").toCharArray();
    }

    private static boolean hasCycle(ListNode head) {
        ListNode quick = head;
        ListNode slow = head;
        while (quick!=null){
            quick = quick.next;
            if (quick == null) return false;
            quick = quick.next;
            if (quick == null) return false;
            slow = slow.next;
            if(quick == slow){
                return true;
            }
        }
        return false;
    }
}
